<?php
    $id = $_GET['id'];
    $db = new Database();
    //$pdf = new FPDF('L','mm','A4');
    $pdf = new FPDF('L','mm','A4');
    
    $pdf->AddPage('L');
    $explode = explode(",",$id);
        if($_GET['action']=="generateAllTag"){
            $rowTagFirst = $db->query("SELECT * FROM tag where fileID = '$id'","array");
            $numRows = $db->query("SELECT * FROM tag where fileID = '$id'","numrows");
            $rowFile = $db->query("SELECT * FROM file where fileID = '$id'","row");
        }elseif($_GET['action']=="singleTagPrint"){
            $rowTagFirst = $db->query("SELECT * FROM tag where id = '$id'","array");
                $row = $db->query("SELECT * FROM tag where id = '$id'","row");
                $imageID = $row['fileID'];
            $numRows = $db->query("SELECT * FROM tag where id = '$id'","numrows");
            $rowFile = $db->query("SELECT * FROM file where fileID = '$imageID'","row");
        }
    $pdf->SetFont('Arial','B',9);
    $pdf->SetFillColor(170, 78, 221);    
        
    
    $pdf->Ln();
    
    if($_GET['action']=="generateAllTag"||$_GET['action']=="singleTagPrint"){
        
        
        $pdf->Ln();
        $pdf->Ln();
        $pdf->Cell(10,5,"Image Name:       ".$rowFile['imageName']);
        $pdf->Ln();
        $pdf->Cell(10,5,"Date Uploaded:   ".$rowFile['dateUploaded']);
        //header
        if($numRows>0){
            $pdf->Ln();
            $width = "23";
            $headTag_first = array("Port","Cabinet","Workstation","Description","IPAddress","MAC","Directory","Station Type","EAPBX","Class Service","V LAN","Local Number");
            $pdf->SetTextColor(255);
            $pdf->SetFont('Arial','',7.5);
            for($a=0;$a<count($headTag_first);$a++){
                $pdf->Cell($width,7,$headTag_first[$a],1,0,'C',true);
            }
            //end header
            $pdf->Ln();
            $pdf->SetFillColor(255,255,255);
            $pdf->SetTextColor(0);
            $pdf->SetFont(''); //set color
            
            //data
            for($count=0;$count<count($explode);$count++){
                foreach($rowTagFirst as $rowTagDataFirst){
                    $pdf->Cell($width,7,$rowTagDataFirst['portNumber'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['cabinet'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['workstation'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['description'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['ipAddress'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['mac'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['directoryName'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['stationType'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['eaPBX'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['classService'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['vLan'],1,0,'C',$fill);
                    $pdf->Cell($width,7,$rowTagDataFirst['localNumber'],1,0,'C',$fill);
                    $pdf->Ln();
                }
            }
        }else{
            $pdf->Ln();
            $pdf->Cell(80,5,"");
            $pdf->Cell(10,15,"( No Tag Found )");
        }
    }elseif($_GET['action']=="printAll"){
        if($id=="undefined"||$id==""){
            $pdf->Ln();
            $pdf->Cell(80,5,"");
            $pdf->Cell(10,15,"( No Selected Found )");
        }else{
            
            $pdf->Ln();
            
            $headTag_first = array("Port","Cabinet","Workstation","Description","IPAddress","MAC","Directory","Station Type","EAPBX","Class Service","V LAN","Local Number");
            $pdf->SetTextColor(255);
            $pdf->SetFont('Arial','',7.5);
            for($a=0;$a<count($headTag_first);$a++){
                $pdf->Cell(16.7,7,$headTag_first[$a],1,0,'C',true);
            }
            //end header
            $pdf->Ln();
            $pdf->SetFillColor(255,255,255);
            $pdf->SetTextColor(0);
            $pdf->SetFont(''); //set color
            
            for($count=0;$count<count($explode);$count++){
                        $rowTagFirst = $db->query("SELECT * FROM tag where id = '$explode[$count]'","array");
                            $row = $db->query("SELECT * FROM tag where id = '$explode[$count]'","row");
                            $imageID = $row['fileID'];
                        $numRows = $db->query("SELECT * FROM tag where id = '$explode[$count]'","numrows");
                        $rowFile = $db->query("SELECT * FROM file where fileID = '$imageID'","row");
                    
                foreach($rowTagFirst as $rowTagDataFirst){
                    $pdf->Cell(16.7,7,$rowTagDataFirst['portNumber'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['cabinet'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['workstation'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['description'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['ipAddress'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['mac'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['directoryName'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['stationType'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['eaPBX'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['classService'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['vLan'],1,0,'C',$fill);
                    $pdf->Cell(16.7,7,$rowTagDataFirst['localNumber'],1,0,'C',$fill);
                    $pdf->Ln();
                }
            }
        }
    }
        
        //end data
    $pdf->Output();
?>